<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
 <h1>getter & setter 2019/2/14 星期四</h1>
<script type="text/javascript">
function log(){
	console.log.apply(this, arguments);
};



/*
function Test1(val) {
  console.log("1");
  this.value123 = val;
}
Test1.prototype = {
  getValue123() {
	console.log("2");
	return this._value;
  },
  setValue123(val) {
	console.log("3");
	this._value = val;
  }
};

var f1 = new Test1("zj");
f1.value123 = "sdf";
f1.setValue123('_value赋值');
console.log(f1);
*/



/*
function Test1(val) {
  console.log("1");
  this.value123 = val;
  this.hobby = 'haha';
}
Test1.prototype = {
  get value123() {
	console.log("2");
	return this._value;
  },
  set value123(val) {
	console.log("3");
	this._value = val;
  }
};

var f1 = new Test1("zj");
f1.value123 = "sdf";
console.log(f1);
*/

/*
class Test2{
  constructor(val){
    console.log("1");
    this.value321 = val;
	this.hobby = 'haha';
  }
  get value321(){
    console.log("2");
    return this._value;
  }
  set value321(v){
    console.log("3");
    this._value=v;
  }
}

var f2 = new Test2("zj");
f2.value321 = "sdf";
console.log(f2);
*/










/*
var arr = [1, 'bb'];
log(arr)
log(arr instanceof Array)

var properties = [],
	ownProperties = [];
for (var i in arr)
{
	properties.push(i);
	if (arr.hasOwnProperty(i))
	{
		ownProperties.push(i);
	}
}
log(properties);
log(ownProperties);





log('\n\n\n')
var brr = new Array(1, 'bb');
log(brr)
log(brr instanceof Array)
*/



function Foo(a, b, c=1){
	log('Foo----', a, b, c);
	this.innerPropertyCommonA = 'Foo this.innerPropertyCommonA';
	this.innerPropertyFooA = 'Foo this.innerPropertyFooA';
	this.innerFuncCommonA = function(fooInnerFuncCommonA) {log('Foo this.innerFuncCommonA()');};
	this.innerFuncFooA = function(fooInnerFuncFooA) {log('Foo this.innerFuncFooA()');};
}

Foo.staticPropertyCommonCount = 'Foo.staticPropertyCommonCount';
Foo.staticPropertyFooCount = 'Foo.staticPropertyFooCount';
Foo.staticFuncCommonA = function(FooStaticFuncCommonA) {log('Foo.staticFuncCommonA()');};
Foo.staticFuncFooA = function(FooStaticFuncFooA) {log('Foo.staticFuncFooA()');};

Foo.prototype.prototypePropertyCommonA = 'Foo.prototype.prototypePropertyCommonA';
Foo.prototype.prototypePropertyFooA = 'Foo.prototype.prototypePropertyFooA';
Foo.prototype.prototypeFuncCommonA = function(FooPrototypePrototypeFuncCommonA) {log('Foo.prototype.prototypeFuncCommonA()');};
Foo.prototype.prototypeFuncFooA = function(FooPrototypePrototypeFuncFooA) {log('Foo.prototype.prototypeFuncFooA()');};

//log(Foo);

//log(Foo.__proto__ === Foo.staticFuncFooA.__proto__);
//log(Foo.__proto__ === Foo.prototype.prototypeFuncCommonA.__proto__);


function Bar(a, b, c=1){
	log('Bar----', a, b, c);
	this.innerPropertyCommonA = 'Bar this.innerPropertyCommonA';
	this.innerPropertyBarA = 'Bar this.innerPropertyBarA';
	this.innerFuncCommonA = function(BarInnerFuncCommonA) {log('Bar this.innerFuncCommonA()');};
	this.innerFuncBarA = function(BarInnerFuncBarA) {log('Bar this.innerFuncBarA()');};
}

Bar.staticPropertyCommonCount = 'Bar.staticPropertyCommonCount';
Bar.staticPropertyBarCount = 'Bar.staticPropertyBarCount';
Bar.staticFuncCommonA = function(BarStaticFuncCommonA) {log('Bar.staticFuncCommonA()');};
Bar.staticFuncBarA = function(BarStaticFuncBarA) {log('Bar.staticFuncBarA()');};

Bar.prototype.prototypePropertyCommonA = 'Bar.prototype.prototypePropertyCommonA';
Bar.prototype.prototypePropertyBarA = 'Bar.prototype.prototypePropertyBarA';
Bar.prototype.prototypeFuncCommonA = function(BarPrototypePrototypeFuncCommonA) {log('Bar.prototype.prototypeFuncCommonA()');};
Bar.prototype.prototypeFuncBarA = function(BarPrototypePrototypeFuncBarA) {log('Bar.prototype.prototypeFuncBarA()');};

//log(Foo.__proto__ === Bar.__proto__);
//log(Foo.__proto__ === Bar.staticFuncCommonA.__proto__);
//log(Foo.__proto__ === Bar.prototype.prototypeFuncBarA.__proto__);

//log(Foo.__proto__.__proto__);
//log(Foo.__proto__.__proto__ === Object.prototype);
//log(Foo.__proto__.__proto__.constructor);
//log(Foo.__proto__.__proto__.constructor.__proto__);


Foo.prototype = new Bar(11, 22, 33);
log(Foo);
log('\n\n');

// arr = ['f', 'f.__proto__', 'f.__proto__.__proto__'];
// property = 'innerPropertyCommonA';
function hasOwnProperty(property, arr=['f', 'f.__proto__', 'f.__proto__.__proto__']){
	for (var val of arr) {
		log(val + '.' + property +' =>', eval(val)[property]);
		log('\t' + val + '.hasOwnProperty('+ property +') =>', eval(val).hasOwnProperty(property));
	}
	log('\n\n');
}

function tc(obj, method){
	try	{
		obj[method]();
	} catch (e) {
		log(e);
	}
}

var f = new Foo(123, 234, 345);
log(f);



//// 内部属性
//hasOwnProperty('innerPropertyCommonA');
//hasOwnProperty('innerPropertyFooA');
//hasOwnProperty('innerPropertyBarA');


//// 原型属性
//hasOwnProperty('prototypePropertyCommonA');
//hasOwnProperty('prototypePropertyFooA');
//hasOwnProperty('prototypePropertyBarA');

//// 内部方法
//tc(f, 'innerFuncCommonA');
//hasOwnProperty('innerFuncCommonA');
//tc(f, 'innerFuncFooA');
//hasOwnProperty('innerFuncFooA');
//tc(f, 'innerFuncBarA');
//hasOwnProperty('innerFuncBarA');


//// 原型方法
//tc(f, 'prototypeFuncCommonA');
//hasOwnProperty('prototypeFuncCommonA');
//tc(f, 'prototypeFuncFooA');
//hasOwnProperty('prototypeFuncFooA');
//tc(f, 'prototypeFuncBarA');
//hasOwnProperty('prototypeFuncBarA');

//// 静态方法
//log(f.__proto__.constructor === f.__proto__.__proto__.constructor);
//log(f.__proto__.constructor);
//log(f.__proto__.__proto__.constructor);
//f.__proto__.__proto__.constructor.staticFuncCommonA();

</script>
 </body>
</html>
